package com.hisense.ovcloud.mqtt.warehouse.config;

import com.hisense.ovcloud.commons.dto.common.DomainInfoDto;
import com.hisense.ovcloud.commons.dto.common.ProductInfoInCache;
import com.hisense.ovcloud.commons.dto.common.mqtt.MqttDeviceInfoInCache;
import com.hisense.ovcloud.commons.dto.common.mqtt.MqttProductInfoInCache;
import com.hisense.ovcloud.commons.tools.LocalLFUCacheUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class LocalCacheConfig {
    private final WarehouseProperties warehouseProperties;

    public LocalCacheConfig(WarehouseProperties warehouseProperties) {
        this.warehouseProperties = warehouseProperties;
    }

    @Bean
    @Qualifier("mqttProductInfoInCache")
    public LocalLFUCacheUtil<MqttProductInfoInCache> mqttProductInfoInCache(){
        return new LocalLFUCacheUtil<>(warehouseProperties.getShortLocalcacheCapacity());
    }

    @Bean
    @Qualifier("mqttDeviceInfoInCache")
    public LocalLFUCacheUtil<MqttDeviceInfoInCache> mqttDeviceInfoInCache(){
        return new LocalLFUCacheUtil<>(warehouseProperties.getLocalcacheCapacity());
    }

    @Bean
    @Qualifier("productInfoInCache")
    public LocalLFUCacheUtil<ProductInfoInCache> productInfoInCache(){
        return new LocalLFUCacheUtil<>(warehouseProperties.getShortLocalcacheCapacity());
    }

    @Bean
    @Qualifier("featureCodeInCache")
    public LocalLFUCacheUtil<DomainInfoDto> featureCodeInCache(){
        return new LocalLFUCacheUtil<>(warehouseProperties.getShortLocalcacheCapacity());
    }
}
